import kotlin.Unit;
import kotlin.jvm.functions.Function1;

import java.io.IOException;

public class JJava {
    private int hitPoints = 2344;

    public String utterGreeting() {
        return "hello";
    }

    public String determineFriendshipLevel() {
        return null;
    }

    public int getHitPoints() {
        System.out.println("------------getHitPoints------------");
        return hitPoints;
    }

    public void setHitPoints(int hitPoints) {
        this.hitPoints = hitPoints;
    }

    public static void main(String[] args) {
        System.out.println(Hero.makeProclamation());

        Spellbook spellbook = new Spellbook();
//        spellbook.getSpell();
        //加了@JvmField以后就可以直接spellbook.spell，没加就要用spellbook.getSpell()
        for (String spell : spellbook.spell) {
            System.out.println(spell);
        }

        //java要支持重载，kt需要添加注解@JvmOverloads
        Hero.handOverFood("apple");

        //伴生对象
//        Spellbook.Companion.getMAX_SPELL_COUNT();
        //添加 @JvmField注解后就可以使用伴生对象里面属性，类似于JAVA里面的STATIC
        System.out.println(Spellbook.MAX_SPELL_COUNT);
        //方法用@JvmStatic
        Spellbook.getSpellbookGreeting();

        try {
            //如果是java需要强制在编译器进行处理
            new JJava().extendHandInFriendship();
        } catch (IOException e) {
            e.printStackTrace();
        }

       try {
           Hero.acceptApology();
           //kt需要增加@Throws(IOException::class)注解，不然就是Throwable t
       } catch (IOException t) {
           System.out.println("catch!");
       }

        Function1<String, Unit> translator = Hero.getTranslator();
       translator.invoke("TRUE");
    }

    public void extendHandInFriendship() throws IOException {
        throw new IOException();
    }
}
